package projetolp2.GraphicInterface;

import java.awt.Component;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.util.List;

import javax.swing.AbstractListModel;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

import projetolp2.Sistem.Sistema;

public class SugestoesTipoCA extends MealPoints implements ActionListener{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private JPanel panelMenu = new JPanel(new GridLayout(0, 1));
	private JPanel panel1 = new JPanel(new GridLayout(0, 1));
	private JPanel panel2 = new JPanel(new GridLayout(0, 1));
	private JButton VOLTAR = new JButton(NomeBotoes.values()[idioma(IDIOMAPROGRAMA )].getVoltar());
	private JLabel label;
	private int quantidade = 0;
	
	public SugestoesTipoCA(){
		
	}private void ajudaDeBotoes(){
		VOLTAR.setToolTipText("Voltar a janela anterior");
	}
	
	public void actionPerformed(ActionEvent e){
		if(e.getSource() == VOLTAR){
			removerAdicionar(((SugestoesTipoCA) sugestoesTipoCA).panel(),sugestoesTipo);
			
		}
	}
	public void quantidade(int valor){
		quantidade = valor;
	}
	@SuppressWarnings("serial")
	private void createComponents() {
		panel1.removeAll();
		panel2.removeAll();
		panelMenu.removeAll();
		ajudaDeBotoes();
		String sugestoes = "Estabelecimento      -      endereço;;;";
		label = new JLabel("Os "+quantidade+" melhores restaurantes: ");
		//TODO
		List<String> listBoteco = Sistema.converteEstabelecimentos(Sistema.recomendacao("cantina", quantidade));
		int  num = 1;
		for(String i : listBoteco){
			sugestoes +=num+" - "+ i+";-----------------------------------------------------;";
			num++;
		}
		JList texto = new JList();
		
		try{
        	final String valorees = sugestoes;
        	//coloca os valores na lista que ira ser mostrada
        texto.setModel(new AbstractListModel() {
        	String[] valores = valorees.split(";");
            public int getSize() { return valores.length; }
            public Object getElementAt(int i) { return valores[i]; }
        });

        texto.setName("jList1"); // NOI18N
        }catch(Exception e){
        	System.err.println(e.getMessage());
        }
		
		panel1.add(new JScrollPane(texto));
		
        VOLTAR.setMnemonic(KeyEvent.VK_I);
        VOLTAR.addActionListener(this);
        label.setLabelFor(VOLTAR);
        
        panel2.add(VOLTAR);
        panel1.setBorder(BorderFactory.createEmptyBorder(
                10, //top
                30, //left
                0, //bottom
                30) //right
                );
        panel2.setBorder(BorderFactory.createEmptyBorder(
                100, //top
                120, //left
                70, //bottom
                120) //right
                );
        panelMenu.add(panel1);
        panelMenu.add(panel2);
        panelMenu.setBorder(BorderFactory.createEmptyBorder(
                30, //top
                30, //left
                10, //bottom
                30) //right
                );
    }
	public Component panel(){
		createComponents();
		panelMenu.setVisible(true);
		
		
		return panelMenu;
	}	
}
